package net.lab1024.sa.admin.module.basedata.customer.controller;

import net.lab1024.sa.admin.module.basedata.customer.domain.dto.CustomerDTO;
import net.lab1024.sa.admin.module.basedata.customer.domain.entity.Customer;
import net.lab1024.sa.admin.module.basedata.customer.domain.form.CustomerQueryForm;
import net.lab1024.sa.admin.module.basedata.customer.service.CustomerService;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/customers")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @GetMapping("/pageList")
    public PageResult<Customer> getAllCustomers(@RequestParam CustomerQueryForm customerQueryForm) {
        return customerService.getAllCustomers(customerQueryForm);
    }

    @GetMapping("/{id}")
    public CustomerDTO getCustomerById(@PathVariable Long id) {
        return customerService.getCustomerById(id);
    }

    @PostMapping("/saveOrUpdateCustomer")
    public ResponseDTO<Object> saveOrUpdateCustomer(@RequestBody CustomerDTO customerDTO) {
         customerService.saveOrUpdateCustomer(customerDTO);
        return ResponseDTO.ok();
    }
    
    

}
